package com.halflife.websocket.entity;

import com.alibaba.fastjson.JSON;

import java.io.*;
import java.util.Base64;

/**
 * Created by zhoumengkang on 16/7/2.
 */
public class Client {
    public static Client getInstance() {
        Client c = new Client();
        c.id = 12;
        c.roomId = 13;
        return c;
    }

    public static void main(String[] args) throws IOException {
        File file = new File("D:/flow.jpg");


        RandomAccessFile randomAccessFile = new RandomAccessFile("d:/flow.jpg","r");
        System.out.println(file.length());
        System.out.println(randomAccessFile.length());
        byte[] bytes  = new byte[(int)randomAccessFile.length()];
        randomAccessFile.read(bytes);

        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        System.out.println(bis.toString());
        bis.close();
        randomAccessFile.close();
        String aa = Base64.getEncoder().encodeToString(bytes);
        System.out.println(aa);
        byte[] bytess = Base64.getDecoder().decode(aa);
        System.out.println(bytes.length);
        System.out.println(bytess.length);
        RandomAccessFile randomAccessFile1 = new RandomAccessFile("d:/flow1.jpg","rw");
        randomAccessFile1.write(bytess);
        randomAccessFile1.close();
        Client client = getFileInstance();
        System.out.println(JSON.toJSONString(client));
    }
    public static Client getFileInstance() throws IOException {
        Client c = new Client();
        c.id = 12;
        c.roomId = 13;
        RandomAccessFile randomAccessFile = new RandomAccessFile("d:/flow.jpg","r");
        c.bytes = new byte[(int)randomAccessFile.length()];
        randomAccessFile.read(c.bytes);
        randomAccessFile.close();
        return c;
    }
    private long id;
    private int roomId;
    private byte[] bytes;

    public Client() {
        id = 0L;
        roomId = 0;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }
}
